package com.carkeeper.controller;

import com.carkeeper.dto.AppraisalDTO;
import com.carkeeper.pojo.MAppraisalPO;
import com.carkeeper.service.OrderAppraisalService;
import com.carkeeper.vo.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;


/**
 * @author: chaolumen
 * @date ：Created in 2020/5/26
 * @description ：
 * @version: 1.0
 */

@RestController
@RequestMapping("/orderAppraisal")
public class OrderAppraisalController {

    @Autowired
    private OrderAppraisalService orderAppraisalService;

    /**
     * 新增评价
     *
     * @param mpo
     */
    @PostMapping
    public Boolean InsertAppraisal(@RequestBody MAppraisalPO mpo) {
        orderAppraisalService.add(mpo);
        return true;
    }

    /**
     * 查询评价
     *
     * @return
     */
    @GetMapping
    public Pager<MAppraisalPO> findAll(@RequestParam(value = "page", defaultValue = "1") Long page,
                                       @RequestParam(value = "pageSize", defaultValue = "10") Long pageSize,
                                       @RequestParam(value = "storeType", required = false) String storeType,
                                       @RequestParam(value = "orderCode", required = false) String orderCode,
                                       @RequestParam(value = "customorName", required = false) String customorName,
                                       @RequestParam(value = "serviceTypeStatus", required = false) Integer serviceTypeStatus,
                                       @RequestParam(value = "orderTimeStart", required = false) String orderTimeStart,
                                       @RequestParam(value = "orderTimeEnd", required = false) String orderTimeEnd,
                                       @RequestParam(value = "storeId", required = false) Long storeId,
                                       @RequestParam(value = "storeName", required = false) String storeName
    ) {


        Pager<MAppraisalPO> result = new Pager<>(orderAppraisalService.findAll(page, pageSize, storeType,
                orderCode, customorName, serviceTypeStatus,
                orderTimeStart, orderTimeEnd, storeName, storeId));
        return result;
    }

    /**
     * 根据id查询评价详情
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public MAppraisalPO findById(@PathVariable String id) {
        return orderAppraisalService.findById(id);
    }

    /**
     * 删除评价
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Boolean deleteAppraisalById(@PathVariable String id) {
        return orderAppraisalService.deleteAppraisalById(id);
    }

    @PostMapping("/list")
    public List<AppraisalDTO> getByIds(@RequestBody List<String> ids) {
        return orderAppraisalService.getByIds(ids);
    }
}



